package com.example.shopdemo.controller.dashboard;

import com.example.shopdemo.entity.HeadLine;
import com.example.shopdemo.entity.ShopCategory;
import com.example.shopdemo.enums.HeadLineStateEnum;
import com.example.shopdemo.enums.ShopCategoryStateEnum;
import com.example.shopdemo.service.HeadLineServiceImpl;
import com.example.shopdemo.service.ShopCategoryServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：Anitaxiaofeng
 * @description：
 * @create 2018-01-24
 **/
@Controller
@RequestMapping("/dashboard")
@Slf4j
public class MainPageController {


    @Autowired
    private ShopCategoryServiceImpl shopCategoryService;

    @Autowired
    private HeadLineServiceImpl headLineService;

    @RequestMapping("/listMainPageInfo")
    @ResponseBody
    public Map<String,Object> listMainPageInfo(){
        Map<String,Object> modelMap = new HashMap<>();
        List<ShopCategory> shopCategoryList = shopCategoryService.queryFirstLevelShopCategory();
        if(shopCategoryList!=null) {
            modelMap.put("shopCategoryList", shopCategoryList);
        }else{
            modelMap.put("success",false);
            modelMap.put("errMsg", ShopCategoryStateEnum.EMPTY.getValue());
            return modelMap;
        }
        List<HeadLine> headLineList = headLineService.getHeadLineList(1);
        if(headLineList!=null){
            modelMap.put("headLineList",headLineList);
        }else{
            modelMap.put("success",false);
            modelMap.put("errMsg", HeadLineStateEnum.EMPTY.getValue());
        }
        modelMap.put("success",true);
        return modelMap;
    }
}






